package ao2udpdemo;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.Scanner;

public class SendMessageDemo {
    public static void main(String[] args) throws IOException {

        //发送数据
        MulticastSocket mr = new MulticastSocket();
        //打包数据
        /*参数1  ：字节数组，存储要发送的数据
        参数2  ：字节数组的长度
        参数3  ：接收方的ip地址
        参数4  ：接收方的端口号*/
        Scanner sc = new Scanner(System.in);
        while (true) {
            String str = sc.next();
            if (str.equals("886")) {
                break;
            }
            byte[] bytes = str.getBytes();
            InetAddress address = InetAddress.getByName("224.0.0.1");
            int port = 10086;
            DatagramPacket dp = new DatagramPacket(bytes,bytes.length,address,port);
            //3.发送数据
            mr.send(dp);
        }

        //释放资源
        mr.close();

    }
}
